﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2.Model
{
    class TransaksiProduk
    {
        public int id;
        int idTransaksi;
        int idKaryawan;
        int idProduk;
        int persentase;
        int nominal;

        public TransaksiProduk()
        {
            
        }

        public TransaksiProduk(int _id)
        {
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM transaksi_produk WHERE id = '" + _id + "'";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            DataRow dr = dt.Rows[0];

            id = (int)dr[0];
            
            db.Close();
        }

        public ArrayList DaftarTransaksiProduk(int _Cabang)
        {
            return null;
        }

        public void AddTransaksiProduk(int _idTransaksi, int _idKaryawan, int _idProduk)
        {
            Database db = new Database();
            long l;
            string sql = "INSERT INTO transaksi_produk(\"ID_Transaksi\", \"ID_Karyawan\", \"ID_Produk\") VALUES (" + _idTransaksi.ToString() + "," + _idKaryawan.ToString() +
                    "," + _idProduk.ToString() + ");select currval('\"transaksi_produk_ID_TransaksiProduk_seq\"')";

            db.Open();
            l = db.ExecuteNonQuery(sql);
            db.Close();

            id = (int)l;
        }

        public void UpdateTransaksiProduk()
        {
        }

        public void DeleteTransaksiProduk()
        {
        }
    }
}
